package com.syq.day2;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.function.IntBinaryOperator;
import java.util.function.IntPredicate;
import java.util.function.Supplier;
import java.util.stream.Stream;


public class Sample2 {

    /**
     * 记录类，JDK16可用
     * @param name
     * @param age
     * @return
     */
//    record Student(String name, int age) {
//    }

    static class Student {
        public String name;
        public int age;
        public Student() {
        }
        public Student(String name, int age) {
            this.name = name;
            this.age = age;
        }
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public int getAge() {
            return age;
        }
        public void setAge(int age) {
            this.age = age;
        }

        @Override
        public String toString() {
            return "Student{name='" + name + "', age=" + age + "}";
        }

        public boolean isOlderThan17() {
            return this.getAge() > 17;
        }
    }

    public static void main(String[] args) {
        Stream.of(
                new Student("张无忌", 18),
                new Student("周芷若", 19),
                new Student("鹿头陀", 17)
        )
//        .filter(stu -> stu.getAge() > 17)
//        .filter(Sample2::isOlderThan17)// 静态方法引用
        .filter(Student::isOlderThan17)// 非静态方法引用
//        .forEach(stu -> System.out.println(stu));// ctrl+P 查看参数
//        .forEach(System.out::println);
        .map(Student::getName)
//        .forEach(Sample2::print);
        .forEach(System.out::println);
    }

    static void print(Student stu){
        System.out.println(stu);
    }

    static boolean isOlderThan17(Student stu) {
        return stu.getAge() > 17;
    }

}
